package com.csnf.servlet;

import com.csnf.dao.ICourseDao;
import com.csnf.dao.lmpl.CourseDaolmpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/course")
public class CourseServlet  extends HttpServlet {
    ICourseDao courseDao = new CourseDaolmpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if (method!=null) {
            try {
                req.setAttribute("courseList", courseDao.getByName(method));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }else{
            try {
                req.setAttribute("courseList", courseDao.getAll());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        req.getRequestDispatcher("/course.jsp").forward(req,resp);
    }
}
